Skip to content

SliceAppearanceProxyModel

Base classes

Name Children Inherits
SliceIdentityProxyModel
prettyqt.itemmodels.proxies.sliceidentityproxymodel
Base model for slice proxy models.

â‹” Inheritance diagram

graph TD
  1441453120["itemmodels.SliceAppearanceProxyModel"]
  4214724289["itemmodels.SliceIdentityProxyModel"]
  527136029["core.IdentityProxyModel"]
  2431222121["core.AbstractProxyModelMixin"]
  3882849576["core.AbstractItemModelMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  3668892142["QtCore.QIdentityProxyModel"]
  3989152870["QtCore.QAbstractProxyModel"]
  1898060022["QtCore.QAbstractItemModel"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  4214724289 --> 1441453120
  527136029 --> 4214724289
  2431222121 --> 527136029
  3882849576 --> 2431222121
  3227531497 --> 3882849576
  2751680898 --> 3227531497
  3668892142 --> 527136029
  3989152870 --> 3668892142
  1898060022 --> 3989152870
  3984060476 --> 1898060022
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: SliceIdentityProxyModel

Source code in prettyqt/itemmodels/proxies/sliceappearanceproxymodel.py
class SliceAppearanceProxyModel(itemmodels.SliceIdentityProxyModel):
    ID = "slice_appearance"
    ICON = "mdi.palette-outline"

    def __init__(
        self,
        foreground: gui.QColor | gui.QBrush | str | None = None,
        background: gui.QColor | gui.QBrush | str | None = None,
        font: str | gui.QFont | None = None,
        alignment: constants.AlignmentFlag | constants.AlignmentStr | None = None,
        override: bool = True,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self._foreground = gui.QColor()
        self.set_foreground(foreground)
        self._background = gui.QColor()
        self.set_background(background)
        self._font = gui.QFont()
        self.set_font(font)
        self._alignment = constants.ALIGN_CENTER_LEFT
        self.set_alignment(alignment)
        self._override = override

    def data(
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        data = super().data(index, role)
        if not self.indexer_contains(index):
            return data
        if self._override or data is None:
            match role:
                case constants.FOREGROUND_ROLE:
                    return self._foreground if self._foreground.isValid() else None
                case constants.BACKGROUND_ROLE:
                    return self._background if self._background.isValid() else None
                case constants.FONT_ROLE:
                    return self._font
                case constants.ALIGNMENT_ROLE:
                    return self._alignment
        return super().data(index, role)

    def set_font(self, font: gui.QFont | str | None):
        self._font = gui.QFont(font) if font else gui.QFont()
        self.update_all()

    def get_font(self) -> gui.QFont:
        return self._font or gui.QFont()

    def set_foreground(self, foreground: datatypes.ColorAndBrushType | None):
        match foreground:
            case None:
                foreground = gui.QColor()
            case gui.QBrush():
                foreground = foreground.color()
            case _:
                foreground = colors.get_color(foreground).as_qt()
        self._foreground = foreground
        self.update_all()

    def get_foreground(self) -> gui.QColor:
        return self._foreground

    def set_background(self, background: datatypes.ColorAndBrushType | None):
        match background:
            case None:
                background = gui.QColor()
            case gui.QBrush():
                background = background.color()
            case _:
                background = colors.get_color(background).as_qt()
        self._background = background
        self.update_all()

    def get_background(self) -> gui.QColor:
        return self._background

    def set_alignment(
        self, alignment: constants.AlignmentFlag | constants.AlignmentStr | None
    ):
        match alignment:
            case None:
                alignment = constants.ALIGN_CENTER_LEFT
            case str() | constants.AlignmentFlag():
                alignment = constants.ALIGNMENTS.get_enum_value(alignment)
        self._alignment = alignment
        self.update_all()

    def get_alignment(self) -> constants.AlignmentFlag:
        return self._alignment

    font_value = core.Property(
        gui.QFont,
        get_font,
        set_font,
        doc="Font to use for overriding",
    )
    foreground_value = core.Property(
        gui.QColor,
        get_foreground,
        set_foreground,
        doc="Foreground to use for overriding",
    )
    background_value = core.Property(
        gui.QColor,
        get_background,
        set_background,
        doc="Background to use for overriding",
    )
    alignment_value = core.Property(
        constants.AlignmentFlag,
        get_alignment,
        set_alignment,
        doc="Alignment to use for overriding",
    )

:fa-brands-github: Show source on GitHub